<template>
	<view class="content" v-if="uiVisible">
		<image class="logo" src="/static/logo.png"></image>
		<text class="title">
			耒耜AI大模型
		</text>
		<view class="subtitle">
			农业领域全智AI大模型
		</view>
		<view style="margin-top: 45px;width:50%; text-align: center;">
			<u-button type="success" icon="weixin-fill" @click="handleWeChatAutoLogin">微信一键登录</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uiVisible:false
			}
		},
		created() {
			if(uni.getStorageSync("token")){
				uni.reLaunch({
					url:"/pages/index/index"
				})
			}else{
				this.uiVisible=true;
			}
		},
		mounted() {
			
		},
		methods: {
			handleWeChatAutoLogin(){
				var _this = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						var params = {
							code: loginRes.code
						}
						console.log(loginRes);
						_this.api.login(params).then(lres => {
							if(lres.code==1){
								_this.$refs.uToast.show({
									type: 'success',
									title: '自动登录成功',
									message: "登录成功!"
								});
								
								uni.setStorageSync("token",lres.token);								
								uni.navigateTo({
									url:"/pages/index/index"
								})
							}
						})
					}
				});
			}
		}
	}
</script>

<style scoped>
   .content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-top: 20px;
   }
   
   .logo {
		height: 256rpx;
		width: 256rpx;
		margin-top: 80rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 20rpx;
   }
   
   .title {
   	font-size: 34rpx;
   	color: #3c3c3e;
   	font-weight: bold;
   }
   
   .subtitle {
   	line-height: 60px;
   	height: 60px;
   }
</style>
